#ifndef SERVICEMANAGER_H
#define SERVICEMANAGER_H

#include <QObject>
#include <QTcpServer>


#include "filelogger.h"
#include "servicefactory.h"
#include "application.h"
#include "applicationconnector.h"

#include "websocketserver.h"

class ApplicationManager : public QObject
{
    Q_OBJECT
public:
    ApplicationManager(QObject *parent = 0);

    /**
     * @brief readConfiguration reads the configuration file 'filename'
     * @param filename is the filename of the configuration file
     */
    void readConfiguration(const QString& filename);


    /**
     * @brief launchApplication launches the application called appName with the arguments stored in args
     * @param appName is the name of the application that is launched
     * @param args is the list of the arguments passed to the application
     */
    void launchApplication(Application *a);

public Q_SLOTS:
    void connectNewClient();

private:
    /**
     * @brief v_logger is the logger of the Service Manager
     */
    FileLogger v_logger;

    /**
     * @brief v_serviceFactory is the factory that stores all the declared services. An application cannot connects to the service manager if it does not provide one of the declared services.
     */
    ServiceFactory v_serviceFactory;
    /**
     * @brief v_applicationMap is the list representing all the currently running applications
     */
    QMap<int, Application*> v_applicationMap;

    //QTcpServer *p_tcpserver;
    WebSocketServer *p_wsserver;
    int v_clientPort;

    QList<ApplicationConnector*> v_connectorList;
};


/**
 * @brief The ServiceManagerException class
 */
class ApplicationManagerException {
public:
    ApplicationManagerException(const QString&)
    {

    }
};

#endif // SERVICEMANAGER_H
